<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/views/include/inc.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/WEB-INF/views/include/head.jsp"%>
<link
	href="<%=contextPath%>/assets/ztree/css/zTreeStyle/zTreeStyle.css"
	rel="stylesheet">
<script src="<%=contextPath%>/assets/ztree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/assets/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript"
	src="<%=contextPath%>/assets/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript">
var zTree;

var setting = {
	view: {
		dblClickExpand: false,
		showLine: true,
		selectedMulti: false
	},
	check: {
		enable: true
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pid",
			rootPId: ""
		}
	},
	async: { //异步加载
        type: "post",
        enable: true,
        url: "<%=contextPath%>/sys/resource/treeData?roleId=${roleId}"
	}
};

$(document).ready(function(){
	var t = $("#tree");
	zTree = $.fn.zTree.init(t, setting);
	
	$("#btn_confirm").click(function(){
		var nodes = zTree.getCheckedNodes(true);
		var ids = new Array(); 
		$(nodes).each(function(i,o){
			ids.push(o.id);
		});
		$.ajax({
		   type: "POST",
		   url: "<%=contextPath%>/sys/role/permission",
		   data: {"id":'${roleId}',"resourcesIds":ids},
		   dataType:"json",  
		   success: function(msg){
		     alert( "Data Saved: " + msg );
		   }
		});
	});
});

</script>
</head>
<body>
	<ul id="tree" class="ztree"
		style="width: 260px; height: 80%; overflow: auto;"></ul>
	<div align="center"
		style="z-index: 1; position: absolute; bottom: 5px; width: 100%">
		<div align="center">
			<a id="btn_confirm" class="btn btn-primary">提交</a>
		</div>
	</div>

</body>
</html>